## Ward, Ezrow, and Dorussen 2011 WP

library(foreign)
library(Amelia)

## Load original dataset
wed2011 <- read.dta("WED2011 WP Rep Data.dta")
head(wed2011)
dim(wed2011)

## Drop ID vars
wed2011$country <- wed2011$ccode <- wed2011$state <- wed2011$party_type <- wed2011$partyname <- wed2011$acra <-  wed2011$marker <-  NULL

## Drop derived dummy vars
wed2011$austria <-wed2011$belgium <-wed2011$denmark <-wed2011$finland <-wed2011$france <- wed2011$greece <-wed2011$ireland <-wed2011$italy <-wed2011$luxembourg <-wed2011$netherlands <-wed2011$portugal <-wed2011$spain <-wed2011$sweden <-wed2011$great_britain <-wed2011$germany <- NULL

## Drop calculated parameters
wed2011$v1 <-wed2011$resid <-wed2011$resid_lag <- wed2011$ui <- wed2011$inportinv <- wed2011$outportinv <- wed2011$prevposition2 <- wed2011$ui <- NULL

which( colnames(wed2011)=="_est_random_effects" )
which( colnames(wed2011)=="_merge" )
wed2011 <- wed2011[, -c(62, 156)]

## How many variables? 156: reduction necessary
dim(wed2011)

## Which variables are in analysis and have missing data?
sum(is.na(wed2011 $position))/nrow(wed2011)*100 ## None
sum(is.na(wed2011 $prevposition))/nrow(wed2011)*100
sum(is.na(wed2011 $vposition))/nrow(wed2011)*100
sum(is.na(wed2011 $economic_globalization))/nrow(wed2011)*100
sum(is.na(wed2011 $vpositionXecon_glob))/nrow(wed2011)*100
sum(is.na(wed2011 $year))/nrow(wed2011)*100 ## None
sum(is.na(wed2011 $totaltrade))/nrow(wed2011)*100
sum(is.na(wed2011 $totaltradeXvposition))/nrow(wed2011)*100
sum(is.na(wed2011 $fdi))/nrow(wed2011)*100
sum(is.na(wed2011 $fdiXvposition))/nrow(wed2011)*100
sum(is.na(wed2011 $quinn_all))/nrow(wed2011)*100
sum(is.na(wed2011 $quinn_allXvposition))/nrow(wed2011)*100
sum(is.na(wed2011 $party))/nrow(wed2011)*100

analysis <- as.data.frame(cbind(wed2011$prevposition, wed2011$vposition, wed2011$economic_globalization, wed2011$vpositionXecon_glob, wed2011$totaltrade, wed2011$totaltradeXvposition, wed2011$fdi, wed2011$fdiXvposition, wed2011$quinn_all, wed2011$quinn_allXvposition))

## Create missingness indicator variables
missing <- as.data.frame(cbind(as.integer(complete.cases(wed2011$prevposition)), as.integer(complete.cases(wed2011$vposition)), as.integer(complete.cases(wed2011$economic_globalization)), as.integer(complete.cases(wed2011$vpositionXecon_glob)), as.integer(complete.cases(wed2011$totaltrade)), as.integer(complete.cases(wed2011$totaltradeXvposition)), as.integer(complete.cases(wed2011$fdi)), as.integer(complete.cases(wed2011$fdiXvposition)), as.integer(complete.cases(wed2011$quinn_all)), as.integer(complete.cases(wed2011$quinn_allXvposition))))

dim(analysis)
dim(missing)
apply(missing, 2, sd)

## Remove analysis variables
## wed2011$prevposition <- wed2011$vposition <-wed2011$economic_globalization <- wed2011$vpositionXecon_glob <- wed2011$totaltrade <-wed2011$totaltradeXvposition <- wed2011$fdi <-wed2011$fdiXvposition <- wed2011$quinn_all <-wed2011$quinn_allXvposition <- NULL
## head(wed2011)
## var(wed2011)

## Check round(correlations and missing values
round(cor(wed2011$diff_pvpos, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$diff_pvpos, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$diff_pvpos))/nrow(wed2011)*100
## Y

round(cor(wed2011$lag_diffpvpos, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$lag_diffpvpos, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$lag_diffpvpos))/nrow(wed2011)*100
## N
wed2011$lag_diffpvpos <- NULL

round(cor(wed2011$lvposition, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$lvposition, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$lvposition))/nrow(wed2011)*100
## N
wed2011$lvposition <- NULL

round(cor(wed2011$dvposition, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$dvposition, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$dvposition))/nrow(wed2011)*100
## N
wed2011$dvposition <- NULL

round(cor(wed2011$quinn_current, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$quinn_current, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$quinn_current))/nrow(wed2011)*100
## N
wed2011$quinn_current <- NULL

round(cor(wed2011$quinn_capital, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$quinn_capital, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$quinn_capital))/nrow(wed2011)*100
## N
wed2011$quinn_capital <- NULL

round(cor(wed2011$quinn_agree, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$quinn_agree, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$quinn_agree))/nrow(wed2011)*100
## N
wed2011$quinn_agree <- NULL

round(cor(wed2011$miniane_cap, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$miniane_cap, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$miniane_cap))/nrow(wed2011)*100
## N
wed2011$miniane_cap <- NULL

round(cor(wed2011$lane_milesi_cap, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$lane_milesi_cap, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$lane_milesi_cap))/nrow(wed2011)*100
## N
wed2011$lane_milesi_cap <- NULL

round(cor(wed2011$infdi, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$infdi, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$infdi))/nrow(wed2011)*100
## Y

round(cor(wed2011$outfdi, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$outfdi, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$outfdi))/nrow(wed2011)*100
## Y

round(cor(wed2011$itrans, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$itrans, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$itrans))/nrow(wed2011)*100
## N
wed2011$itrans <- NULL

round(cor(wed2011$dposition, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$dposition, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$dposition))/nrow(wed2011)*100
## N
wed2011$dposition <- NULL

round(cor(wed2011$dfdi, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$dfdi, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$dfdi))/nrow(wed2011)*100
## N
wed2011$dfdi <- NULL

round(cor(wed2011$dtotaltrade, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$dtotaltrade, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$dtotaltrade))/nrow(wed2011)*100
## N
wed2011$dtotaltrade <- NULL

round(cor(wed2011$dquinn_capital, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$dquinn_capital, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$dquinn_capital))/nrow(wed2011)*100
## N
wed2011$dquinn_capital <- NULL

round(cor(wed2011$dprevposition, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$dprevposition, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$dprevposition))/nrow(wed2011)*100
## N
wed2011$dprevposition <- NULL

round(cor(wed2011$actual_economic_flows, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$actual_economic_flows, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$actual_economic_flows))/nrow(wed2011)*100
## N
wed2011$actual_economic_flows <- NULL

round(cor(wed2011$economic_restrictions, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$economic_restrictions, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$economic_restrictions))/nrow(wed2011)*100
## N
wed2011$economic_restrictions <- NULL

round(cor(wed2011$social_globalization, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$social_globalization, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$social_globalization))/nrow(wed2011)*100
## N
wed2011$social_globalization <- NULL

round(cor(wed2011$political_globalization, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$political_globalization, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$political_globalization))/nrow(wed2011)*100
## N
wed2011$political_globalization <- NULL

round(cor(wed2011$globalization_index, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$globalization_index, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$globalization_index))/nrow(wed2011)*100
## N
wed2011$globalization_index <- NULL

round(cor(wed2011$obs_per_party, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$obs_per_party, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$obs_per_party))/nrow(wed2011)*100
## N
wed2011$obs_per_party <- NULL

round(cor(wed2011$adams_haupf, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$adams_haupf, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$adams_haupf))/nrow(wed2011)*100
## N
wed2011$adams_haupf <- NULL

round(cor(wed2011$actual_economic_flowsXvposition, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$actual_economic_flowsXvposition, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$actual_economic_flowsXvposition))/nrow(wed2011)*100
## Y

round(cor(wed2011$leftXopeness, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$leftXopeness, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$leftXopeness))/nrow(wed2011)*100
## N
wed2011$leftXopeness <- NULL

round(cor(wed2011$left, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$left, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$left))/nrow(wed2011)*100
## N
wed2011$left <- NULL

round(cor(wed2011$vpositionXopeness, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$vpositionXopeness, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$vpositionXopeness))/nrow(wed2011)*100
## Y

round(cor(wed2011$time_since, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$time_since, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$time_since))/nrow(wed2011)*100
## N
wed2011$time_since <- NULL

round(cor(wed2011$time_sinceXprevposition, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$time_sinceXprevposition, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$time_sinceXprevposition))/nrow(wed2011)*100
## Y

round(cor(wed2011$portfolio1, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$portfolio1, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$portfolio1))/nrow(wed2011)*100
## Y

round(cor(wed2011$portfolio2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$portfolio2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$portfolio2))/nrow(wed2011)*100
## Y

round(cor(wed2011$portfolio3, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$portfolio3, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$portfolio3))/nrow(wed2011)*100
## N
wed2011$portfolio3 <- NULL

round(cor(wed2011$portfolio4, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$portfolio4, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$portfolio4))/nrow(wed2011)*100
## N
wed2011$portfolio4 <- NULL

round(cor(wed2011$decon_globXdvposition, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$decon_globXdvposition, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$decon_globXdvposition))/nrow(wed2011)*100
## N
wed2011$decon_globXdvposition <- NULL

round(cor(wed2011$price_level, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$price_level, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$price_level))/nrow(wed2011)*100
## N
wed2011$price_level <- NULL

round(cor(wed2011$growth, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$growth, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$growth))/nrow(wed2011)*100
## N
wed2011$growth <- NULL

round(cor(wed2011$inflation, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$inflation, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$inflation))/nrow(wed2011)*100
## N
wed2011$inflation <- NULL

round(cor(wed2011$lprevposition, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$lprevposition, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$lprevposition))/nrow(wed2011)*100
## N
wed2011$lprevposition <- NULL

round(cor(wed2011$herfgov, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$herfgov, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$herfgov))/nrow(wed2011)*100
## N
wed2011$herfgov <- NULL

round(cor(wed2011$herfopp, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$herfopp, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$herfopp))/nrow(wed2011)*100
## N
wed2011$herfopp <- NULL

round(cor(wed2011$herftot, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$herftot, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$herftot))/nrow(wed2011)*100
## N
wed2011$herftot <- NULL

round(cor(wed2011$oppfrac, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$oppfrac, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$oppfrac))/nrow(wed2011)*100
## N
wed2011$oppfrac <- NULL

round(cor(wed2011$frac, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$frac, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$frac))/nrow(wed2011)*100
## N
wed2011$frac <- NULL

round(cor(wed2011$govfrac, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$govfrac, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$govfrac))/nrow(wed2011)*100
## N
wed2011$govfrac <- NULL

round(cor(wed2011$effectiveparties, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$effectiveparties, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$effectiveparties))/nrow(wed2011)*100
## N
wed2011$effectiveparties <- NULL

round(cor(wed2011$pervote, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$pervote, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$pervote))/nrow(wed2011)*100
## N
wed2011$pervote <- NULL

round(cor(wed2011$absseat, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$absseat, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$absseat))/nrow(wed2011)*100
## N
wed2011$absseat <- NULL

round(cor(wed2011$totseats, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$totseats, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$totseats))/nrow(wed2011)*100
## Y

round(cor(wed2011$perseats, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$perseats, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$perseats))/nrow(wed2011)*100
## N
wed2011$perseats <- NULL

round(cor(wed2011$dvpositionXecon_glob, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$dvpositionXecon_glob, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$dvpositionXecon_glob))/nrow(wed2011)*100
## N
wed2011$dvpositionXecon_glob <- NULL

round(cor(wed2011$lagposition, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$lagposition, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$lagposition))/nrow(wed2011)*100
## Y

round(cor(wed2011$leftXecon_glob, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$leftXecon_glob, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$leftXecon_glob))/nrow(wed2011)*100
## N
wed2011$leftXecon_glob <- NULL

round(cor(wed2011$soc_dem, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$soc_dem, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$soc_dem))/nrow(wed2011)*100
## N
wed2011$soc_dem <- NULL

round(cor(wed2011$soc_demXecon_glob, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$soc_demXecon_glob, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$soc_demXecon_glob))/nrow(wed2011)*100
## N
wed2011$soc_demXecon_glob <- NULL

round(cor(wed2011$con, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$con, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$con))/nrow(wed2011)*100
## N
wed2011$con <- NULL

round(cor(wed2011$conXecon_glob, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$conXecon_glob, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$conXecon_glob))/nrow(wed2011)*100
## N
wed2011$conXecon_glob <- NULL

round(cor(wed2011$lib, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$lib, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$lib))/nrow(wed2011)*100
## N
wed2011$lib <- NULL

round(cor(wed2011$libXecon_glob, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$libXecon_glob, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$libXecon_glob))/nrow(wed2011)*100
## N
wed2011$libXecon_glob <- NULL

round(cor(wed2011$econ_resXvposition, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$econ_resXvposition, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$econ_resXvposition))/nrow(wed2011)*100
## N
wed2011$econ_resXvposition <- NULL

round(cor(wed2011$warwick_econ_glob, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$warwick_econ_glob, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$warwick_econ_glob))/nrow(wed2011)*100
## N
wed2011$warwick_econ_glob <- NULL

round(cor(wed2011$warwick_soc_glob, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$warwick_soc_glob, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$warwick_soc_glob))/nrow(wed2011)*100
## N
wed2011$warwick_soc_glob <- NULL

round(cor(wed2011$warwick_pol_glob, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$warwick_pol_glob, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$warwick_pol_glob))/nrow(wed2011)*100
## N
wed2011$warwick_pol_glob <- NULL

round(cor(wed2011$warwick_overall_glob, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$warwick_overall_glob, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$warwick_overall_glob))/nrow(wed2011)*100
## N
wed2011$warwick_overall_glob <- NULL

round(cor(wed2011$war_econ_globXvposition, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$war_econ_globXvposition, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$war_econ_globXvposition))/nrow(wed2011)*100
## N
wed2011$war_econ_globXvposition <- NULL

round(cor(wed2011$lnwarwick_econ_glob, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$lnwarwick_econ_glob, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$lnwarwick_econ_glob))/nrow(wed2011)*100
## N
wed2011$lnwarwick_econ_glob <- NULL

round(cor(wed2011$lnwar_econ_globXvposition, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$lnwar_econ_globXvposition, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$lnwar_econ_globXvposition))/nrow(wed2011)*100
## N
wed2011$lnwar_econ_globXvposition <- NULL

round(cor(wed2011$corporatism, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$corporatism, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$corporatism))/nrow(wed2011)*100
## N
wed2011$corporatism <- NULL

round(cor(wed2011$centralization, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$centralization, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$centralization))/nrow(wed2011)*100
## N
wed2011$centralization <- NULL

round(cor(wed2011$centXleft, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$centXleft, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$centXleft))/nrow(wed2011)*100
## N
wed2011$centXleft <- NULL

round(cor(wed2011$kenwcoor, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$kenwcoor, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$kenwcoor))/nrow(wed2011)*100
## N
wed2011$kenwcoor <- NULL

round(cor(wed2011$lijphart_corporatism, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$lijphart_corporatism, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$lijphart_corporatism))/nrow(wed2011)*100
## N
wed2011$lijphart_corporatism <- NULL

round(cor(wed2011$leftXl_corp, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$leftXl_corp, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$leftXl_corp))/nrow(wed2011)*100
## N
wed2011$leftXl_corp <- NULL

round(cor(wed2011$leftXkenwcoor, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$leftXkenwcoor, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$leftXkenwcoor))/nrow(wed2011)*100
## N
wed2011$leftXkenwcoor <- NULL

round(cor(wed2011$leftgovvote, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$leftgovvote, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$leftgovvote))/nrow(wed2011)*100
## N
wed2011$leftgovvote <- NULL

round(cor(wed2011$leftgovseat, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$leftgovseat, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$leftgovseat))/nrow(wed2011)*100
## N
wed2011$leftgovseat <- NULL

round(cor(wed2011$sleftgovseat, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$sleftgovseat, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$sleftgovseat))/nrow(wed2011)*100
## N
wed2011$sleftgovseat <- NULL

round(cor(wed2011$sleftgovseatXleft, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$sleftgovseatXleft, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$sleftgovseatXleft))/nrow(wed2011)*100
## N
wed2011$sleftgovseatXleft <- NULL

round(cor(wed2011$sc_vposition, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$sc_vposition, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$sc_vposition))/nrow(wed2011)*100
## Y

round(cor(wed2011$leftv, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$leftv, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$leftv))/nrow(wed2011)*100
## Y

round(cor(wed2011$ecglobXleftv, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$ecglobXleftv, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$ecglobXleftv))/nrow(wed2011)*100
## Y

round(cor(wed2011$leftvXkenwcoor, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$leftvXkenwcoor, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$leftvXkenwcoor))/nrow(wed2011)*100
## N
wed2011$leftvXkenwcoor <- NULL

round(cor(wed2011$per503, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$per503, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$per503))/nrow(wed2011)*100
## N
wed2011$per503 <- NULL

round(cor(wed2011$per504, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$per504, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$per504))/nrow(wed2011)*100
## N
wed2011$per504 <- NULL

round(cor(wed2011$per505, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$per505, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$per505))/nrow(wed2011)*100
## N
wed2011$per505 <- NULL

round(cor(wed2011$per506, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$per506, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$per506))/nrow(wed2011)*100
## N
wed2011$per506 <- NULL

round(cor(wed2011$per507, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$per507, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$per507))/nrow(wed2011)*100
## N
wed2011$per507 <- NULL

round(cor(wed2011$welfare, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$welfare, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$welfare))/nrow(wed2011)*100
## N
wed2011$welfare <- NULL

round(cor(wed2011$welfaremp, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$welfaremp, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$welfaremp))/nrow(wed2011)*100
## N
wed2011$welfaremp <- NULL

round(cor(wed2011$educmp, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$educmp, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$educmp))/nrow(wed2011)*100
## N
wed2011$educmp <- NULL

round(cor(wed2011$prevwelfaremp, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$prevwelfaremp, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$prevwelfaremp))/nrow(wed2011)*100
## N
wed2011$prevwelfaremp <- NULL

round(cor(wed2011$preveducmp, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$preveducmp, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$preveducmp))/nrow(wed2011)*100
## N
wed2011$preveducmp <- NULL

round(cor(wed2011$lib_world, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$lib_world, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$lib_world))/nrow(wed2011)*100
## N
wed2011$lib_world <- NULL

round(cor(wed2011$soc_dem_world, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$soc_dem_world, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$soc_dem_world))/nrow(wed2011)*100
## N
wed2011$soc_dem_world <- NULL

round(cor(wed2011$cons_world, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$cons_world, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$cons_world))/nrow(wed2011)*100
## N
wed2011$cons_world <- NULL

round(cor(wed2011$EUaccession, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$EUaccession, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$EUaccession))/nrow(wed2011)*100
## Y

round(cor(wed2011$tEUaccession, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$tEUaccession, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$tEUaccession))/nrow(wed2011)*100
## Y

round(cor(wed2011$nposition, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$nposition, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$nposition))/nrow(wed2011)*100
## Y

round(cor(wed2011$prevnposition, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$prevnposition, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$prevnposition))/nrow(wed2011)*100
## Y

round(cor(wed2011$econ_position, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$econ_position, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$econ_position))/nrow(wed2011)*100
## Y

round(cor(wed2011$prevecon_pos, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$prevecon_pos, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$prevecon_pos))/nrow(wed2011)*100
## Y

round(cor(wed2011$cgdp, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$cgdp, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$cgdp))/nrow(wed2011)*100
## N
wed2011$cgdp <- NULL

round(cor(wed2011$pop, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$pop, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$pop))/nrow(wed2011)*100
## N
wed2011$pop <- NULL

round(cor(wed2011$expa_eu, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$expa_eu, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$expa_eu))/nrow(wed2011)*100
## Y

round(cor(wed2011$impa_eu, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$impa_eu, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$impa_eu))/nrow(wed2011)*100
## N
wed2011$impa_eu <- NULL

round(cor(wed2011$impa_eu2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$impa_eu2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$impa_eu2))/nrow(wed2011)*100
## Y

round(cor(wed2011$expa_eu2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$expa_eu2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$expa_eu2))/nrow(wed2011)*100
## Y

round(cor(wed2011$eu_open, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$eu_open, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$eu_open))/nrow(wed2011)*100
## N
wed2011$eu_open <- NULL

round(cor(wed2011$eu_open_2, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$eu_open_2, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$eu_open_2))/nrow(wed2011)*100
## N
wed2011$eu_open_2 <- NULL

round(cor(wed2011$check, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$check, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$check))/nrow(wed2011)*100
## N
wed2011$check <- NULL

round(cor(wed2011$eu_openXvposition, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$eu_openXvposition, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$eu_openXvposition))/nrow(wed2011)*100
## Y

round(cor(wed2011$eu_open_2Xvposition, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$eu_open_2Xvposition, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$eu_open_2Xvposition))/nrow(wed2011)*100
## Y

round(cor(wed2011$plurality, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$plurality, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$plurality))/nrow(wed2011)*100
## Y

round(cor(wed2011$prDPI, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$prDPI, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$prDPI))/nrow(wed2011)*100
## N
wed2011$prDPI <- NULL

round(cor(wed2011$eta, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$eta, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$eta))/nrow(wed2011)*100
## N
wed2011$eta <- NULL

round(cor(wed2011$vpositionXeu_open, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$vpositionXeu_open, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$vpositionXeu_open))/nrow(wed2011)*100
## Y

round(cor(wed2011$median, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$median, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$median))/nrow(wed2011)*100
## Y

round(cor(wed2011$medianXecon_glob, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$medianXecon_glob, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$medianXecon_glob))/nrow(wed2011)*100
## Y

round(cor(wed2011$right, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$right, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$right))/nrow(wed2011)*100
## N
wed2011$right <- NULL

round(cor(wed2011$z_vposition, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$z_vposition, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$z_vposition))/nrow(wed2011)*100
## Y

round(cor(wed2011$z_vpositionXecon_glob, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$z_vpositionXecon_glob, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$z_vpositionXecon_glob))/nrow(wed2011)*100
## Y

round(cor(wed2011$degree, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$degree, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$degree))/nrow(wed2011)*100
## N
wed2011$degree <- NULL

round(cor(wed2011$igo_degree, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$igo_degree, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$igo_degree))/nrow(wed2011)*100
## Y

round(cor(wed2011$vpositionXigo_degree, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$vpositionXigo_degree, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$vpositionXigo_degree))/nrow(wed2011)*100
## Y

round(cor(wed2011$lvpositionXigo_degree, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$lvpositionXigo_degree, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$lvpositionXigo_degree))/nrow(wed2011)*100
## N
wed2011$lvpositionXigo_degree <- NULL

round(cor(wed2011$linflation, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$linflation, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$linflation))/nrow(wed2011)*100
## N
wed2011$linflation <- NULL

round(cor(wed2011$lgrowth, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$lgrowth, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$lgrowth))/nrow(wed2011)*100
## N
wed2011$lgrowth <- NULL

round(cor(wed2011$party_type_lr, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$party_type_lr, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$party_type_lr))/nrow(wed2011)*100
## Y

round(cor(wed2011$lecon_glob, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$lecon_glob, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$lecon_glob))/nrow(wed2011)*100
## N
wed2011$lecon_glob <- NULL

round(cor(wed2011$vpositionXlecon_glob, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$vpositionXlecon_glob, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$vpositionXlecon_glob))/nrow(wed2011)*100
## Y

round(cor(wed2011$pecon_glob, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$pecon_glob, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$pecon_glob))/nrow(wed2011)*100
## Y

round(cor(wed2011$vpositionXpecon_glob, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$vpositionXpecon_glob, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$vpositionXpecon_glob))/nrow(wed2011)*100
## N
wed2011$vpositionXpecon_glob <- NULL

round(cor(wed2011$leftXvpositionXecon_glob, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$leftXvpositionXecon_glob, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$leftXvpositionXecon_glob))/nrow(wed2011)*100
## N
wed2011$leftXvpositionXecon_glob <- NULL

round(cor(wed2011$leftXvposition, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$leftXvposition, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$leftXvposition))/nrow(wed2011)*100
## N
wed2011$leftXvposition <- NULL

round(cor(wed2011$h_g_coordination, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$h_g_coordination, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$h_g_coordination))/nrow(wed2011)*100
## N
wed2011$h_g_coordination <- NULL

round(cor(wed2011$l_c_corporatism, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$l_c_corporatism, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$l_c_corporatism))/nrow(wed2011)*100
## N
wed2011$l_c_corporatism <- NULL

round(cor(wed2011$l_c_cons_dem, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$l_c_cons_dem, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$l_c_cons_dem))/nrow(wed2011)*100
## N
wed2011$l_c_cons_dem <- NULL

round(cor(wed2011$h_g_bjps_lab_rel, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$h_g_bjps_lab_rel, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$h_g_bjps_lab_rel))/nrow(wed2011)*100
## N
wed2011$h_g_bjps_lab_rel <- NULL

round(cor(wed2011$h_g_bjps_corp_gov, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$h_g_bjps_corp_gov, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$h_g_bjps_corp_gov))/nrow(wed2011)*100
## N
wed2011$h_g_bjps_corp_gov <- NULL

round(cor(wed2011$h_g_bjps_composite, analysis, use = "pairwise.complete.obs"), 2)
round(cor(wed2011$h_g_bjps_composite, missing, use = "pairwise.complete.obs"), 2)
sum(is.na(wed2011$h_g_bjps_composite))/nrow(wed2011)*100
## N
wed2011$h_g_bjps_composite <- NULL

## Imputation
head(wed2011)
dim(wed2011)

## What is average percentage of missing data?
NAs <- function(x) {
    as.vector(apply(x, 2, function(x) length(which(is.na(x)))))
    }
NAs(wed2011)
mean(NAs(wed2011)/nrow(wed2011))*100

## Thus: 12 imputations

## Note: already lag for position
set.seed(02138)
wed2011.out <- amelia(wed2011, m = 12, cs = "party", ts = "year", polytime = 3, lags = c("vpositionXecon_glob", "economic_globalization", "vposition"), empri = 0.01*nrow(wed2011))

write.amelia(obj=wed2011.out, file.stem = "WED2011 WP Imp Data", format = "dta", separate = FALSE)
